package Niuke;
import java.util.Scanner;
public class Main{
    public static class area{

        int x1,y1;

        char char1;

        int x2,y2;

        char char2;

        int x3,y3;

        char char3;


        public area(int x1,int y1,char char1,int x2,int y2,char char2,int x3,int y3,char char3){
            this.x1=x1;
            this.x2=x2;
            this.x3=x3;
            this.y1=y1;
            this.y2=y2;
            this.y3=y3;
            this.char1=char1;
            this.char2=char2;
            this.char3=char3;
        }

        public boolean contains(int num){
            if (Character.isDigit(char1)){
                int i = Integer.parseInt(char1 + "");
                if (i==num) return true;
            }
            if (Character.isDigit(char2)){
                int i = Integer.parseInt(char2 + "");
                if (i==num) return true;
            }
            if (Character.isDigit(char3)){
                int i = Integer.parseInt(char3 + "");
                if (i==num) return true;
            }
            return false;
        }

        public boolean belong(int x,int y){
            if ((x==x1&&y==y1)||(x==x2&&y==y2)||(x==x3&&y==y3))
                return true;
            return false;
        }


    }

    public static int cnt=0;
    public static char[][] res=new char[3][3];
    public static void main(String[] args) {
        Scanner s= new Scanner(System.in);
        int o= s.nextInt();
        area a1=null,a2=null,a3=null;
        for (int p=1;p<=o;p++){
            char[][] chars=new char[3][3];
            for (int i=0;i<3;i++){
                String ss=s.next();
                char[] chars1 = ss.toCharArray();
                for (int j=0;j<3;j++){
                    chars[i][j]=chars1[j];
                }
            }
            for (int i=1;i<=3;i++){
                int x1=s.nextInt();
                int y1=s.nextInt();
                int x2=s.nextInt();
                int y2=s.nextInt();
                int x3=s.nextInt();
                int y3=s.nextInt();
                if (i==1) a1=new area(x1,y1,chars[x1][y1],x2,y2,chars[x2][y2],x3,y3,chars[x3][y3]);
                if (i==2) a2=new area(x1,y1,chars[x1][y1],x2,y2,chars[x2][y2],x3,y3,chars[x3][y3]);
                if (i==3) a3=new area(x1,y1,chars[x1][y1],x2,y2,chars[x2][y2],x3,y3,chars[x3][y3]);
            }
            Main.distiguish(a1,a2,a3,chars,0,0);
            if (cnt==1){
                System.out.println("Unique");
                for (int i=0;i<3;i++){
                    for (int j=0;j<3;j++){
                        System.out.print(res[i][j]);
                    }
                    System.out.println();
                }
                cnt=0;
            }else if (cnt>1){
                System.out.println("Multiple");
                cnt=0;
            }else {
                System.out.println("No");
            }
        }

    }

    public static void distiguish(area a1,area a2,area a3,char[][] chars,int x,int y){
        if (x==2&&y==3){
            if (dis(chars)) cnt++;
            for (int i=0;i<3;i++){
                for (int j=0;j<3;j++){
                    res[i][j]=chars[i][j];
                }
            }
        }
        if (y==3){
            x++;
            if (x==3) return;
            y=0;
        }
        if (!Character.isDigit(chars[x][y])) {
            for (int i = 1; i <= 3; i++) {
                if (a1.belong(x, y)) {
                    if (check(chars,x,y,i)&&(!a1.contains(i))){
                        chars[x][y]=(i+"").toCharArray()[0];
                        distiguish(a1,a2,a3,chars,x,y+1);
                        chars[x][y]='*';
                    }
                }
                else if (a2.belong(x, y)) {
                    if (check(chars,x,y,i)&&(!a2.contains(i))){
                        chars[x][y]=(i+"").toCharArray()[0];
                        distiguish(a1,a2,a3,chars,x,y+1);
                        chars[x][y]='*';
                    }
                }
                else if (a3.belong(x, y)) {
                    if (check(chars,x,y,i)&&(!a3.contains(i))){
                        chars[x][y]=(i+"").toCharArray()[0];
                        distiguish(a1,a2,a3,chars,x,y+1);
                        chars[x][y]='*';
                    }
                }
            }
        }else {
            distiguish(a1,a2,a3,chars,x,y+1);
        }
    }

    public static boolean check(char[][] chars,int x,int y,int num){
        for (int i=0;i<3;i++){
            if (Character.isDigit(chars[x][i])){
                int t=Integer.parseInt(chars[x][i]+"");
                if (t==num) return false;
            }
            if (Character.isDigit(chars[i][y])){
                int t=Integer.parseInt(chars[i][y]+"");
                if (t==num) return false;
            }
        }
        return true;
    }

    public static boolean dis(char[][] chars){
        for (int i=0;i<3;i++){
            for (int j=0;j<3;j++){
                if (!Character.isDigit(chars[i][j])) return false;
            }
        }
        return true;
    }

}
